package com.leezk.order.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.leezk.order.constant.CommonConstant;
import com.leezk.order.dto.ResultDTO;
import com.leezk.order.dto.TagMapperDto;
import com.leezk.order.entity.Dictionary;
import com.leezk.order.entity.Menu;
import com.leezk.order.service.IDictionaryService;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author leotong
 * @since 2022-03-16
 */
@RestController
@RequestMapping(CommonConstant.API_URI_VERSION_V1+"/dictionary")
public class DictionaryController {

    @Autowired
    private IDictionaryService dictionaryService;

    @GetMapping("/getDictionarys")
    public ResultDTO<Page<Dictionary>> getDictionarys(int pageNum, int pageSize){
        Page<Dictionary> page=new Page<>(pageNum,pageSize);
        return ResultDTO.success(dictionaryService.getDictionarys(page));
    }

    @GetMapping("/getValidDic")
    public ResultDTO<List<Dictionary>> getValidDic(){
        return ResultDTO.success(dictionaryService.getValidDic());
    }

    @GetMapping("/getUseDic")
    public ResultDTO<List<TagMapperDto>> getUseDic(int studentId){
        return ResultDTO.success(dictionaryService.getUseDic(studentId));
    }

    @PostMapping("/addDic")
    public ResultDTO<Boolean> addDic(@RequestBody Dictionary dictionary){
        return ResultDTO.success(dictionaryService.addDic(dictionary));
    }
    @GetMapping("/delDic")
    public ResultDTO<Boolean> deleteDic(int id){
        return ResultDTO.success(dictionaryService.deleteDic(id));
    }
}
